package practite.sort;

import java.util.Arrays;
import java.util.Random;

/**
 * 希尔排序存疑
 */
public class ShellSort {
    public static void main(String[] args) {
        int[] array = getRandomArray();
        for (int gap = array.length/2; gap > 0; gap/=2) {
            for (int i = gap; i < array.length; i++) {
                for (int j = i - gap; j >=0 ; j-=gap) {
                    if (array[j]>array[j+gap]){
                        int max = array[j];
                        array[j] = array[j+gap];
                        array[j+gap] = max;
                        System.out.println(Arrays.toString(array));
                    }

                    
                }
                System.out.println();
            }

            System.out.println(Arrays.toString(array));
        }

        System.out.println(Arrays.toString(array));
    }

    //生成随机数
    public static int getRandom(){
        Random random = new Random();
        int a = random.nextInt(100)+1;
        return a;
    }

    //生成随机数的十位数组
    public static int[] getRandomArray(){
        int[] a = new int[10];
        for (int i = 0; i < a.length; i++) {
            a[i] = getRandom();

        }
        return a;
    }

}
